<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   重庆时时彩
 */
defined('IN_YuLin') || exit('NO PERMIT!');

//	计算两个值：money（投注金额），orders（订单数组），plays（玩法）
$money = 0;
$orders = [];
$plays = [];

foreach($nums as $val)
{
	//	再来一注，ItemId对应pid
	$itemid = intval($val['ItemId']);
	if($itemid > 0)
	{
		$val['i']	=	$itemid;
		$val['m']	=	$val['MoneyModel'];
		$val['t']	=	$val['Times'];
		$val['n']	=	$val['BetNumber'];
		$val['c']	=	$val['Content'];
	}
	
	$playid = intval($val['i']);
	if(!$playid)
	{
		continue;
	}
	
	$tmp = $db->getrow('SELECT * FROM '.$ptable.' WHERE playid = '.$playid.' AND status = 1 AND cid = '.$cid);
	if(!$tmp)
	{
		continue;
	}
	$plays[] = $tmp;
	
	//	单位1、2、3对应元角分
	$unit = intval($val['m']);
	$units = [1=>1,2=>0.1,3=>0.01];
	!array_key_exists($unit,$units) && $unit = 1;
	
	//	倍数
	$times = max(1,intval($val['t']));
	
	//	注数
	$multiple = max(1,intval($val['n']));
	
	//	彩票号
	$rednum = NoBadStr($val['c']);
	if(!$rednum)
	{
		continue;
	}
	
	$ins = [];
	$ins['uid']		=	$_uid;
	$ins['cid']		=	$cid;
	$ins['iid']		=	$iid;
	$ins['pid']		=	$playid;
	$ins['period']	=	$period;
	$ins['rednum']	=	$rednum;
	$ins['times']	=	$times;
	$ins['multiple']=	$multiple;
	$ins['unit']	=	$unit;
	$ins['money']	=	$multiple * $times * 2 * $units[$unit];
	$ins['dateline']=	TIMESTAMP;
	$orders[] = $ins;
	
	$money += $ins['money'];
}
